package kr.saeildamil.androidforstudy2.ch20;

import kr.saeildamil.androidforstudy2.R;
import kr.saeildamil.androidforstudy2.ch20.common.CounterFragment03;
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class FragmentArgument extends Activity {
	EditText mStartNum;
	
		@Override
		protected void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			setContentView(R.layout.ch20_fragmentargument);
			
			mStartNum = (EditText) findViewById(R.id.ch20_fragmentargument_startnum);
		
			getFragmentManager().beginTransaction().add(new CounterFragment03().newInstance(1), "counter").commit();
		
		}
		
		public void mOnClick(View v){
			switch (v.getId()) {
			case R.id.ch20_fragmentargument_addbtn:
				FragmentManager fm = getFragmentManager();
				FragmentTransaction ft = fm.beginTransaction();
				int start = Integer.parseInt(mStartNum.getText().toString());
				
				CounterFragment03 cf = CounterFragment03.newInstance(start);
				
				ft.replace(R.id.ch20_fragmentargument_frame, cf, "counter");
				ft.addToBackStack(null);
				ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
				ft.commit();
				break;
			}
		}
}
